import {HTTP} from '../util/http.js'
class ClassicModel extends HTTP {
  getLatest(sCallback) {
    this.request({
      url: 'latest',
      success: (res) => {
        sCallback(res)
        this._setLatestIndex(res.data.result[0].index)
      }
    })
  }

  getClassic(index, nextOrPrevious, sCallback) {
    this.request({
      url: 'classic/' + index + '/' + nextOrPrevious,
      success: (res) => {
        sCallback(res)
      }
    })
  }

  getNext() {

  }

  isFirst(index) {
    return index === 1 ? true : false
  }

  isLatest(index) {
    let latestIndex = this._getLatestIndex()
    return latestIndex === index ? true : false
  }

  // 保存最新的期刊
  _setLatestIndex(index) {
    wx.setStorageSync('latest', index)
  }
  // 获取
  _getLatestIndex() {
    let index = wx.getStorageSync('latest')
    // wx.getStorage({
    //   key: 'latest'
    // })
    return index
  }
}

export {ClassicModel}